/*
 * @Description:
 * @Version:
 * @Autor: ps
 * @Date: 2022-07-04 13:17:53
 * @LastEditors: ps
 * @LastEditTime: 2022-07-04 13:58:48
 */
import Vue from 'vue'

import Cookies from 'js-cookie'

import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/skst.scss' // skst css
import 'leaflet/dist/leaflet.css'; //leaflet css
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins
import { download } from '@/utils/request'
// 引入电子签名
import vueEsign from "vue-esign";
// 使用电子签名
Vue.use(vueEsign);
import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/skst";
import VueComp from '@/directive/components'
// 头部标签组件
import VueMeta from 'vue-meta'
// 字典数据组件
import DictData from '@/components/DictData'
// 数字滚动组件
import VueAnimateNumber from 'vue-animate-number'
// 高德地图
import VueAMap from 'vue-amap';
import webSocket from '@/utils/webSocket.js';

// import CryptoJS from 'crypto-js';
// Vue.prototype.$CryptoJS = CryptoJS;

// canvas绘制工具
import fabric from "fabric"
Vue.use(fabric)


// 全局方法挂载
Vue.prototype.$webSocket = webSocket
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.$bus = new Vue()

// 全局组件挂载
Vue.use(directive)
Vue.use(plugins)
Vue.use(VueComp)
Vue.use(VueAnimateNumber)
Vue.use(VueMeta)
Vue.use(VueAMap)
DictData.install()

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */
// 初始化高德地图的 key 和插件
VueAMap.initAMapApiLoader({
  key: "193e00fee6b0740a0c3c2ab0946e873f",
  plugin: [
    "AMap.Autocomplete",
    //输入提示插件
    "AMap.PlaceSearch",
    //POI搜索插件
    "AMap.Scale",
    //右下角缩略图插件 比例尺
    "AMap.OverView",
    //地图鹰眼插件
    "AMap.ToolBar",
    //地图工具条
    "AMap.MapType",
    //类别切换控件，实现默认图层与卫星图、实施交通图层之间切换的控制
    "AMap.PolyEditor",
    //编辑 折线多，边形
    "AMap.CircleEditor",
    'MarkerClusterer', // 点聚合
    //圆形编辑器插件
    "AMap.Geolocation",
    'AMap.DistrictSearch',
    'Geocoder',
    "AMap.BesizerCurve",
    'AMap.Geocoder',
    "AMap.MouseTool", // 鼠标工具插件
  ],
  v: '1.4.15', // 默认高德 sdk 版本为 1.4.4
  uiVersion: '1.0.11'
});
//高德的安全密钥
window._AMapSecurityConfig = {
  securityJsCode: 'da8bd0845af0127c18097e7bba1240d2',
}

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

// vue每次版本更新强刷页面
const version = require('../package.json').version
const versionStorage = localStorage.getItem('version')
console.log('最新版本', 'v' + version)
console.log('缓存版本', 'v' + versionStorage)

if (version != versionStorage) {
  localStorage.clear()
  localStorage.setItem('version', version)
  // console.log('版本不一致，清除缓存中')
  //location.reload() 方法用来刷新当前页面。该方法只有一个参数，当值为 true 时，将强制浏览器从服务器加载页面资源，
  //当值为 false 或者未传参时，浏览器则可能从缓存中读取页面。
  setTimeout(() => {
    window.location.reload(true)
  }, 1000)
}

